import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;

import java.awt.Color;
import java.io.IOException;

import com.googlecode.grtframework.event.AccelerometerEvent;
import com.googlecode.grtframework.event.AccelerometerListener;
import com.googlecode.grtframework.rpc.USBRPC;
import com.googlecode.grtframework.sensor.IAccelerometer;
import com.googlecode.grtframework.sensor.RPCAccelerometer;
import com.googlecode.gunncs.graph.TimedLinePlot;

/**
 * Displays acceleration data
 * 
 * @author ajc
 * 
 */
public class RPCAccelerationTest implements AccelerometerListener {

	private TimedLinePlot lp;

	public RPCAccelerationTest(RPCAccelerometer accel) {
		lp = new TimedLinePlot("acceleration", 500);
		lp.addData("" + IAccelerometer.X, Color.GREEN, "m/s");
		lp.addData("" + IAccelerometer.Y, Color.ORANGE, "m/s");
		lp.addData("" + IAccelerometer.Z, Color.YELLOW, "m/s");
		accel.addAccelerometerListener(this);
	}

	@Override
	public void accelerationChanged(AccelerometerEvent e) {
		lp.addPoint("" + e.getAxis(), e.getAcceleration());
	}

	public static void main(String[] args) {
		USBRPC conn = null;
		try {
			conn = new USBRPC("/dev/ttyACM0");
		} catch (NoSuchPortException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (PortInUseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		RPCAccelerometer r = new RPCAccelerometer(conn,
				new int[] { 66, 67, 68 });
		r.startListening();
		RPCAccelerationTest test = new RPCAccelerationTest(r);

	}

}
